var ytviidx = 1, ytvipls = [], ytvi_ajaxContinue = true, max_results = 10;
function loadVideos (auth, url) {
  var max_result = 10, ytviidx = 1, ytvipls = [], ytvi_ajaxContinue = true;
  console.log("aaaa");
  auth.authorize();
  var token = auth.getAccessToken();
  while (true) {
    try {
      $.ajax({
        'url':  url+'&alt=json&oauth_token='+token+'&max-results='+max_results+'&start-index='+ytviidx,
        'dataType': 'json',
        'async':    false,
        statusCode: {
          401:  function(){throw "oautherror"; } // token error
        },
        'headers':  {
          'Authorization':  'OAuth ' + token
        },
        ajaxContinue: ytvi_ajaxContinue,
        success:    function(obj) {
          ytvi_ajaxContinue = this.ajaxContinue;
          if (obj.feed.entry == undefined || obj.feed.entry.length == 0){
            ytvi_ajaxContinue = false;
            return;
          }
          for (var i in obj.feed.entry) {
            ytvipls.push(obj.feed.entry[i].media$group.yt$videoid["$t"]);
            if (ytvipls.length == parseInt(obj.feed.openSearch$totalResults["$t"], 10)) {
              ytvi_ajaxContinue = false;
              break;
            }
          }
        }
      });
      if (ytvi_ajaxContinue == false) {
        throw "nonext";
        break;
      }
      ytviidx += max_results;
    } catch (err) {
      if (err != "nonext") {
        console.log(err);
      }
      break;
    }
  }
  return ytvipls;
}